package org.yankun.exam4j.core.result.service.impl;

import java.io.Serializable;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.yankun.exam4j.common.daobase.DaoBase;
import org.yankun.exam4j.core.result.service.ResultService;
import org.yankun.exam4j.entity.Result;

@Transactional
@Service
public class ResultServiceImpl implements ResultService {

	@Resource
	private DaoBase<Result> dao;
	
	@Override
	public Result getResultById(Serializable resultId) {
		return dao.getHibernateTemplate().get(Result.class, resultId);
	}
	
	
	
	@Override
	public Result getResultbyPaperIdAndUserId(Serializable paperId,
			Serializable userId) {
		
		String hql = " from Result where paper.uid = ? and user.uid = ?";
		
		List<Result> resultList = dao.hql(hql, 1, new Object[]{paperId,userId});
		
		if(resultList != null && !resultList.isEmpty()){
			return resultList.get(0);
		}
		
		return null;
	}

	
	
	@Override
	public void save(Result result) {
		dao.save(result);
	}



	@Override
	public void update(Result result) {
		dao.update(result);
	}

}
